﻿var customerCollapse=undefined;
var customerExpand=undefined;
var dataKeyList='';

function changePwd(){
	if(!this.ppc){
		this.ppc=new Chenxin.UI.PersonalPwdChange('');
	}
	this.ppc.show();
	this.ppc.setTitle('修改密码');
}

function switchSysBar(){
	var aaa = document.getElementById("aaa");
	if (aaa.src.indexOf("bl_1")!=-1){
	   aaa.src="/images/al_1.gif";
	   $("#frmTitle").hide();
	   $("#left-menu").css('width','13px');
	   $('.tabsorternew').each(function(){  
			$(this.parentNode).css('width',$(this.parentNode.parentNode).css('width')); 
	   });
	    $('.x-grid-dom').each(function(){  
			$(this).css('width',($(this).width()+152)+'px'); 
	   });
		if(customerCollapse){
			customerCollapse();
		}
	}else{
		aaa.src="/images/bl_1.gif";
		$("#frmTitle").show();
		$("#left-menu").css('width','163px');
		try{
			$('.x-grid-dom').each(function(){  
				$(this).css('width',($(this).width()-152)+'px'); 
		   });
			$('.tabsorternew').each(function(i){
				if($(this.parentNode.parentNode).css('width')==$(this.parentNode).css('width')){
					var width=parseInt($(this.parentNode.parentNode).css('width').replace('px','')-152);
					$(this.parentNode).css('width',width+'px');       

				}else{
					$(this.parentNode).css('width',$(this.parentNode.parentNode).css('width'));                 
				}
			

			}); 
	   }catch(e){
	   
	   }
	   
		if(customerExpand){
			customerExpand();
		}
	}
}


function initLeftMenu(){
	hidAllChildren();

    $("#menu li").each(function(){
	    var bShow;
	    bShow = false;
	    $(this).find("a").each(function(){
	        if( $(this).attr("href") != "#"){
	            if( $(this).attr("display") != "none" ){
	                bShow = true;
	            }
	        }
	    });
	    if( bShow == false ){
	        $(this).hide();
	    }else{
	        $(this).show();
	    }
	});
	
	$("#menu a").each(function() {
		var aUrl = $(this).attr("href").toLower();
		var curUrl = location.href.toLower();
		curUrl = curUrl.substring(curUrl.lastIndexOf("/") + 1);
		aUrl = aUrl.substring(aUrl.lastIndexOf("/") + 1);
		
		curUrl = curUrl.replace("#","");
		if(curUrl.indexOf("?type=") == -1){
		    
		    curUrl = curUrl.replace(/\?.+/,"");
		    aUrl = aUrl.replace(/\?.+/,"");
		}
		if( curUrl==aUrl ){
	        $(this).parents("ul:first").slideDown("fast");
	        return;
	    }
	});
}
function hidAllChildren(){
	$("#menu").find("li").find("ul").hide();
}    

function getDataDictionary(){	
	if(!dataKeyList){
		return;
	}
	Chenxin.ajax({
		type: "post",
		dataType: "text",
		paramType: 'json',
		async:false,
		url: '/service/housemgr.ashx',
		data: { op: 'getdatadictionary',datakeylist:dataKeyList},
		onSuccess: function(data, msg) {
			Chenxin.data.dictionary=data;
		}
	});
}

$(document).ready(function(){        

	$("#menu").click(function(event){
		if(event.target.tagName == "A"){
			if($(event.target).attr("href") == "#"){
				hidAllChildren();
				$(event.target).parent("li").children("ul").slideDown("slow");
			}
		}
	});

	$('#pwdchange').click(function(){
		changePwd();
	});
	
	initLeftMenu();
	getDataDictionary();
	// debugger;
	// alert($($('#mainbodynew').childrenNode[0]).css('width'));
});